package com.hmdp.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * redisson分布式锁 引入依赖，创建客户端，调用客户端创建锁
 * <dependency>
 * <groupId>org.redisson</groupId>
 * <artifactId>redisson</artifactId>
 * <version>3.13.6</version>
 * </dependency>
 * //锁对象创建
 * RLock lock = redissonClient.getLock("lock:order:" + userId);
 * boolean isLock = lock.tryLock(,,);//括号内三个参数分别是，获取锁的最大等待时间(期间会重试)，锁自动释放时间，时间单位
 */
@Configuration
public class RedissonConfig {
    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://192.168.58.129:6379").setPassword("123456");
        return Redisson.create(config);
    }
}
